package org.djustice.apkgot;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View;


/**
 * @author djustice
 *
 */
public class MainActivity extends ListActivity {

    String site = "";

    @Override
    public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	this.setTitle("apkGot");

	TextView v = new TextView(this);
	v.setText("Select a source:");
	getListView().addHeaderView(v, null, false);

	String[] sites = getResources().getStringArray(R.array.sites);
	String list = "";

	for (String s : sites) {
	    list += s.split(";")[0] + "\n";
	}

	this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list.split("\n")));
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
	super.onListItemClick(l, v, position, id);

	Object o = getListView().getItemAtPosition(position);
	String keyword = o.toString();
	site = keyword;
	Toast.makeText(this, "You selected: " + keyword, Toast.LENGTH_LONG).show();

	Intent i = new Intent(this, PackageListActivity.class);
	i.putExtra("source_site", site);
	startActivityForResult(i, 0);
	
//	Intent i = new Intent(this, BatchDownloadActivity.class);
//	startActivityForResult(i, 0);
	
	this.setVisible(false);
    }
    
    @Override
    protected void onResume() {
	this.setVisible(true);
	Toast.makeText(this, "Test", Toast.LENGTH_LONG);

	super.onResume();
    }
}

